//买卖股票的最佳时机
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int prev_min = prices[0];
        int ret = 0;
        for (int i = 1; i < prices.size(); i++) {
            if (prev_min > prices[i]) {
                prev_min = prices[i];
            } else {
                ret = max(ret, prices[i] - prev_min);
            }
        }
        return ret;
    }
};

//买卖股票的最佳时机II
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int prev = 0;
        int ret = 0;
        for (int i = 0; i < prices.size(); i++) {
            if (prices[i] > prices[prev])
                ret += (prices[i] - prices[prev]);
            prev = i;
        }
        return ret;
    }
};

